package com.xiaotu.test;

import com.xiaotu.common.redis.RedisClientTemplate;
import com.xiaotu.server.service.guduo.SupplementGuDuoRecordService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RefreshTVPlayCountRedisData {

    /**
     * 腾讯累计播放量任务
     */
    public static final String QQ_PLAY_COUNT_TASK = "QQ_PLAY_COUNT_TASK";
    /**
     * 搜狐累计播放量任务
     */
    public static final String SOHU_PLAY_COUNT_TASK = "SOHU_PLAY_COUNT_TASK";

    /**
     * 芒果TV累计播放量任务
     */
    public static final String MGTV_PLAY_COUNT_TASK = "MGTV_PLAY_COUNT_TASK";
    /**
     * 爱奇艺热度任务
     */
    public static final String IQY_HEAT_TASK = "IQY_HEAT_TASK";
    /**
     * 优酷热度任务
     */
    public static final String YOUKU_HEAT_TASK = "YOUKU_HEAT_TASK";

    /**
     * 全部任务
     */
    public static final String TV_TYPE_135_LIST = "TV_TYPE_135_LIST";


    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:application-context.xml");
        RedisClientTemplate redis = context.getBean("redisClientTemplate", RedisClientTemplate.class);
        Map<String, String> siteMap = new HashMap<String, String>();
        //腾讯视频 电视剧，网剧，电影，累计播放量
//        siteMap.put("siteName","腾讯视频");
//        QQPlayCountTask(context,redis,siteMap);
        //搜狐视频 电视剧，网剧，电影，累计播放量
//        siteMap.put("siteName","搜狐视频");
//        SouHuPlayCountTask(context, redis, siteMap);
//        siteMap.put("siteName","芒果TV");
//        MGTVPlayCountTask(context, redis, siteMap);


//        siteMap.put("siteName","爱奇艺");
//        IQYHeatTask(context, redis, siteMap);
//        siteMap.put("siteName", "优酷");
//        YOUKUHeatTask(context, redis, siteMap);

        allTask(context, redis);

    }


    public static void allTask(ApplicationContext context, RedisClientTemplate redis){
        SupplementGuDuoRecordService service = context.getBean("supplementGuDuoRecordService", SupplementGuDuoRecordService.class);
        List<Map<String, Object>> list = null;
        if (!list.isEmpty() && list.size() > 0) {
            redis.del(TV_TYPE_135_LIST);
            for (Map<String, Object> tvInfo : list) {
                String tvid = tvInfo.get("tvid") == null ? "" : tvInfo.get("tvid").toString();
                String tvName = tvInfo.get("tvname") == null ? "" : tvInfo.get("tvname").toString();
                String tvType = tvInfo.get("tvtype") == null ? "" : tvInfo.get("tvtype").toString();
                String alias = tvInfo.get("alias") == null ? "" : tvInfo.get("alias").toString();
                String firstPlayTime = tvInfo.get("firstplaytime") == null ? "" : tvInfo.get("firstplaytime").toString();
                String director = tvInfo.get("director") == null ? "" : tvInfo.get("director").toString();
                String actor = tvInfo.get("actor") == null ? "" : tvInfo.get("actor").toString();
                String platform = tvInfo.get("platform") == null ? "" : tvInfo.get("platform").toString();
                redis.hset(TV_TYPE_135_LIST, tvid, "{'tvid':'" + tvid + "','tvName':'" + tvName +
                        "','tvType':'" + tvType + "','alias':'" +
                        alias + "','firstPlayTime':'" + firstPlayTime +
                        "','director':'" + director + "','actor':'" + actor +
                        "','platform':'" + platform + "'}");
            }
        }
    }

    /**
     * 腾讯视频 电视剧，网剧，电影，累计播放量
     *
     * @param context
     * @param redis
     */
    public static void QQPlayCountTask(ApplicationContext context, RedisClientTemplate redis, Map<String, String> siteMap) {
        SupplementGuDuoRecordService service = context.getBean("supplementGuDuoRecordService", SupplementGuDuoRecordService.class);
        List<Map<String, Object>> list = null;
        if (!list.isEmpty() && list.size() > 0) {
            redis.del(QQ_PLAY_COUNT_TASK);
            for (Map<String, Object> tvInfo : list) {
                String tvid = tvInfo.get("tvid") == null ? "" : tvInfo.get("tvid").toString();
                String tvName = tvInfo.get("tvname") == null ? "" : tvInfo.get("tvname").toString();
                String tvType = tvInfo.get("tvtype") == null ? "" : tvInfo.get("tvtype").toString();
                String alias = tvInfo.get("alias") == null ? "" : tvInfo.get("alias").toString();
                String firstPlayTime = tvInfo.get("firstplaytime") == null ? "" : tvInfo.get("firstplaytime").toString();
                String director = tvInfo.get("director") == null ? "" : tvInfo.get("director").toString();
                String actor = tvInfo.get("actor") == null ? "" : tvInfo.get("actor").toString();
                String platform = tvInfo.get("platform") == null ? "" : tvInfo.get("platform").toString();
                redis.hset(QQ_PLAY_COUNT_TASK, tvid, "{'tvid':'" + tvid + "','tvName':'" + tvName +
                        "','tvType':'" + tvType + "','alias':'" +
                        alias + "','firstPlayTime':'" + firstPlayTime +
                        "','director':'" + director + "','actor':'" + actor +
                        "','platform':'" + platform + "'}");
            }
        }
    }

    /**
     * 腾讯视频 电视剧，网剧，电影，累计播放量
     *
     * @param context
     * @param redis
     */
    public static void SouHuPlayCountTask(ApplicationContext context, RedisClientTemplate redis, Map<String, String> siteMap) {
        SupplementGuDuoRecordService service = context.getBean("supplementGuDuoRecordService", SupplementGuDuoRecordService.class);
        List<Map<String, Object>> list = null;
        if (!list.isEmpty() && list.size() > 0) {
            redis.del(SOHU_PLAY_COUNT_TASK);
            for (Map<String, Object> tvInfo : list) {
                String tvid = tvInfo.get("tvid") == null ? "" : tvInfo.get("tvid").toString();
                String tvName = tvInfo.get("tvname") == null ? "" : tvInfo.get("tvname").toString();
                String tvType = tvInfo.get("tvtype") == null ? "" : tvInfo.get("tvtype").toString();
                String alias = tvInfo.get("alias") == null ? "" : tvInfo.get("alias").toString();
                String firstPlayTime = tvInfo.get("firstplaytime") == null ? "" : tvInfo.get("firstplaytime").toString();
                String director = tvInfo.get("director") == null ? "" : tvInfo.get("director").toString();
                String actor = tvInfo.get("actor") == null ? "" : tvInfo.get("actor").toString();
                String platform = tvInfo.get("platform") == null ? "" : tvInfo.get("platform").toString();
                redis.hset(SOHU_PLAY_COUNT_TASK, tvid, "{'tvid':'" + tvid + "','tvName':'" + tvName +
                        "','tvType':'" + tvType + "','alias':'" +
                        alias + "','firstPlayTime':'" + firstPlayTime +
                        "','director':'" + director + "','actor':'" + actor +
                        "','platform':'" + platform + "'}");
            }
        }
    }

    /**
     * 芒果TV 电视剧，网剧，电影，累计播放量
     *
     * @param context
     * @param redis
     */
    public static void MGTVPlayCountTask(ApplicationContext context, RedisClientTemplate redis, Map<String, String> siteMap) {
        SupplementGuDuoRecordService service = context.getBean("supplementGuDuoRecordService", SupplementGuDuoRecordService.class);
        List<Map<String, Object>> list = null;
        if (!list.isEmpty() && list.size() > 0) {
            redis.del(MGTV_PLAY_COUNT_TASK);
            for (Map<String, Object> tvInfo : list) {
                String tvid = tvInfo.get("tvid") == null ? "" : tvInfo.get("tvid").toString();
                String tvName = tvInfo.get("tvname") == null ? "" : tvInfo.get("tvname").toString();
                String tvType = tvInfo.get("tvtype") == null ? "" : tvInfo.get("tvtype").toString();
                String alias = tvInfo.get("alias") == null ? "" : tvInfo.get("alias").toString();
                String firstPlayTime = tvInfo.get("firstplaytime") == null ? "" : tvInfo.get("firstplaytime").toString();
                String director = tvInfo.get("director") == null ? "" : tvInfo.get("director").toString();
                String actor = tvInfo.get("actor") == null ? "" : tvInfo.get("actor").toString();
                String platform = tvInfo.get("platform") == null ? "" : tvInfo.get("platform").toString();
                redis.hset(MGTV_PLAY_COUNT_TASK, tvid, "{'tvid':'" + tvid + "','tvName':'" + tvName +
                        "','tvType':'" + tvType + "','alias':'" +
                        alias + "','firstPlayTime':'" + firstPlayTime +
                        "','director':'" + director + "','actor':'" + actor +
                        "','platform':'" + platform + "'}");
            }
        }
    }

    /**
     * 爱奇艺热度任务
     *
     * @param context
     * @param redis
     */
    public static void IQYHeatTask(ApplicationContext context, RedisClientTemplate redis, Map<String, String> siteMap) {
        SupplementGuDuoRecordService service = context.getBean("supplementGuDuoRecordService", SupplementGuDuoRecordService.class);
        List<Map<String, Object>> list = null;
        if (!list.isEmpty() && list.size() > 0) {
            redis.del(IQY_HEAT_TASK);
            for (Map<String, Object> tvInfo : list) {
                String tvid = tvInfo.get("tvid") == null ? "" : tvInfo.get("tvid").toString();
                String tvName = tvInfo.get("tvname") == null ? "" : tvInfo.get("tvname").toString();
                String tvType = tvInfo.get("tvtype") == null ? "" : tvInfo.get("tvtype").toString();
                String alias = tvInfo.get("alias") == null ? "" : tvInfo.get("alias").toString();
                String firstPlayTime = tvInfo.get("firstplaytime") == null ? "" : tvInfo.get("firstplaytime").toString();
                String director = tvInfo.get("director") == null ? "" : tvInfo.get("director").toString();
                String actor = tvInfo.get("actor") == null ? "" : tvInfo.get("actor").toString();
                String platform = tvInfo.get("platform") == null ? "" : tvInfo.get("platform").toString();
                redis.hset(IQY_HEAT_TASK, tvid, "{'tvid':'" + tvid + "','tvName':'" + tvName +
                        "','tvType':'" + tvType + "','alias':'" +
                        alias + "','firstPlayTime':'" + firstPlayTime +
                        "','director':'" + director + "','actor':'" + actor +
                        "','platform':'" + platform + "'}");
            }
        }
    }

    /**
     * 优酷热度任务
     *
     * @param context
     * @param redis
     */
    public static void YOUKUHeatTask(ApplicationContext context, RedisClientTemplate redis, Map<String, String> siteMap) {
        SupplementGuDuoRecordService service = context.getBean("supplementGuDuoRecordService", SupplementGuDuoRecordService.class);
        List<Map<String, Object>> list = null;
        if (!list.isEmpty() && list.size() > 0) {
            redis.del(YOUKU_HEAT_TASK);
            for (Map<String, Object> tvInfo : list) {
                String tvid = tvInfo.get("tvid") == null ? "" : tvInfo.get("tvid").toString();
                String tvName = tvInfo.get("tvname") == null ? "" : tvInfo.get("tvname").toString();
                String tvType = tvInfo.get("tvtype") == null ? "" : tvInfo.get("tvtype").toString();
                String alias = tvInfo.get("alias") == null ? "" : tvInfo.get("alias").toString();
                String firstPlayTime = tvInfo.get("firstplaytime") == null ? "" : tvInfo.get("firstplaytime").toString();
                String director = tvInfo.get("director") == null ? "" : tvInfo.get("director").toString();
                String actor = tvInfo.get("actor") == null ? "" : tvInfo.get("actor").toString();
                String platform = tvInfo.get("platform") == null ? "" : tvInfo.get("platform").toString();
                redis.hset(YOUKU_HEAT_TASK, tvid, "{'tvid':'" + tvid + "','tvName':'" + tvName +
                        "','tvType':'" + tvType + "','alias':'" +
                        alias + "','firstPlayTime':'" + firstPlayTime +
                        "','director':'" + director + "','actor':'" + actor +
                        "','platform':'" + platform + "'}");
            }
        }
    }

}
